package com.benben.springSecurity.weiwei;

public class longestHuiwen {
    public static void main(String[] args){
        int L=0;
        int R = 4;
        int start = 0;
        int end =0;
        while(L>=0&&R<5){
            L--;
            R++;
        }
        int len = R-L-1;
        System.out.println("the len is:"+len);
        if (len > 0) {
            start = 2 - (len - 1) / 2;
            end = 2 + len / 2;
        }
        System.out.println(start + " " + end);
    }
    /////
    public String longestPalindrome(String s){
        if(s == null || s.length()==0){
            return "";
        }
        int start =0;
        int end = 0;
        for(int i=0;i<s.length();i++){
            int len1 = expandAroundCenter(s,i,i);
            int len2 = expandAroundCenter(s,i,i+1);
            int len = Math.max(len1,len2);
            if(len>end -start){
                start = i-(len-1)/2;
                end = i + len/2;
            }
        }
        return s.substring(start,end+1);
    }
    public int expandAroundCenter(String s,int left,int right){
        while(left>=0 && right<s.length() && s.charAt(left) == s.charAt(right)){
            left--;
            right++;
        }
        return right-left-1;
    }
}
